<?php echo $header; ?>
<div id="content">
    <div class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
    </div>
    <?php if ($error_warning) { ?>
    <div class="warning"><?php echo $error_warning; ?></div>
    <?php } ?>
    <?php if ($success) { ?>
    <div class="success"><?php echo $success; ?></div>
    <?php } ?>
    <div class="box">
        <div class="heading">
            <h1><img src="view/image/category.png" alt="" /> <?php echo $heading_title; ?></h1>
            <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a></div>
        </div>
        <div class="content">
            <form action="" method="post" id="form">
                <table id="cron" class="list">
                    <thead>
                    <tr>
                        <td class="left"><span class="required">*</span> <?php echo $entry_name; ?></td>
                        <td class="left"><span class="required">*</span> <?php echo $entry_file_name; ?></td>
                        <td class="left"><?php echo $entry_status; ?></td>
                        <td class="left"><?php echo $entry_log; ?></td>
                        <td class="left"><?php echo $entry_execute_time; ?></td>
                        <td class="left"><?php echo $entry_last_execute_time; ?></td>
                        <td class="left"><?php echo $entry_next_execute_time; ?></td>
                        <td></td>
                        <td></td>
                    </tr>
                    </thead>
                    <?php $cron_row = 0; ?>
                    <?php foreach ($crons as $cron) { ?>
                    <tbody id="cron-row<?php echo $cron_row; ?>">
                    <tr>
                        <td class="left">
                            <input type="hidden" name="cron[<?php echo $cron_row; ?>][cron_id]" value="<?php echo $cron['cron_id']; ?>" />
                            <input type="text" name="cron[<?php echo $cron_row; ?>][name]" value="<?php echo $cron['name']; ?>" size="30" />
                         <?php if (isset($error_cron_name[$cron_row])) { ?>
                         <span class="error"><?php echo $error_cron_name[$cron_row]; ?></span>
                         <?php } ?>
                        </td>
                        <td class="left">
                            <input type="text" name="cron[<?php echo $cron_row; ?>][file_name]" value="<?php echo $cron['file_name']; ?>" size="30" />
                            <?php if (isset($error_cron_file_name[$cron_row])) { ?>
                            <span class="error"><?php echo $error_cron_file_name[$cron_row]; ?></span>
                            <?php } ?>
                        </td>
                        <td class="left"><select name="cron[<?php echo $cron_row; ?>][available]">
                            <?php if($cron['next_run']){ ?>
                                <?php if($cron['available']){ ?>
                                <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                                <option value="0"><?php echo $text_disabled; ?></option>
                                <?php }else{ ?>
                                <option value="1"><?php echo $text_enabled; ?></option>
                                <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                                <?php } ?>
                            <?php }else{ ?>
                                <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                            <?php } ?>
                        </select></td>
                        <td class="left"><select name="cron[<?php echo $cron_row; ?>][logging]">
                            <?php if($cron['logging']){ ?>
                            <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                            <option value="0"><?php echo $text_disabled; ?></option>
                            <?php }else{ ?>
                            <option value="1"><?php echo $text_enabled; ?></option>
                            <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                            <?php } ?>
                        </select></td>
                        <td class="left">
                            <input type="hidden" name="cron[<?php echo $cron_row; ?>][execute_time]" value="<?php echo $cron['execute_time']; ?>" />
                            <input type="hidden" name="cron[<?php echo $cron_row; ?>][month]" value="<?php echo $cron['month']; ?>" />
                            <input type="hidden" name="cron[<?php echo $cron_row; ?>][weekday]" value="<?php echo $cron['weekday']; ?>" />
                            <input type="hidden" name="cron[<?php echo $cron_row; ?>][day]" value="<?php echo $cron['day']; ?>" />
                            <input type="hidden" name="cron[<?php echo $cron_row; ?>][hour]" value="<?php echo $cron['hour']; ?>" />
                            <input type="hidden" name="cron[<?php echo $cron_row; ?>][minute]" value="<?php echo $cron['minute']; ?>" />
                            <?php echo $cron['execute_time']; ?>
                        </td>
                        <td class="left">
                            <input type="hidden" name="cron[<?php echo $cron_row; ?>][last_run]" value="<?php echo $cron['last_run']; ?>" />
                            <?php echo $cron['last_run_text']; ?>
                        </td>
                        <td class="left">
                            <input type="hidden" name="cron[<?php echo $cron_row; ?>][next_run]" value="<?php echo $cron['next_run']; ?>" />
                            <?php echo $cron['next_run_text']; ?>
                        </td>
                        <td class="left">
                           <?php if($cron['cron_id']){ ?>
                            <a href="<?php echo $cron['cron_edit']; ?>"><?php echo $button_edit; ?></a><br /><br />
                            <a href="<?php echo $cron['cron_execute']; ?>"><?php echo $button_execute; ?></a>
                            <?php } ?>
                        </td>
                        <td class="right"><a onclick="$('#cron-row<?php echo $cron_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
                    </tr>
                    </tbody>
                    <?php $cron_row++; ?>
                    <?php } ?>
                    <tfoot>
                    <tr>
                        <td colspan="8"></td>
                        <td class="right"><a onclick="addCron();" class="button"><?php echo $button_add; ?></a></td>
                    </tr>
                    </tfoot>
                </table>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript"><!--
var cron_row = <?php echo $cron_row; ?>;

function addCron() {
    html  = '<tbody id="cron-row' + cron_row + '">';
    html += '<tr>';
    html += '<td class="left"><input type="hidden" name="cron[' + cron_row + '][cron_id]" value="" />';
    html += '<input type="text" name="cron[' + cron_row + '][name]" value="" size="30" />';
    html += '</td>';
    html += '<td class="left"><input type="text" name="cron[' + cron_row + '][file_name]" value="" size="30" /></td>';
    html += '<td class="left"><select name="cron[' + cron_row + '][available]">';
    html += '<option value="0" selected="selected">' + '<?php echo $text_disabled; ?>' + '</option>';
    html += '</select></td>';
    html += '<td class="left"><select name="cron[' + cron_row + '][logging]">';
    html += '<option value="0" selected="selected">' + '<?php echo $text_disabled; ?>' + '</option>';
    html += '</select></td>';
    html += '<td class="left"><input type="hidden" name="cron[' + cron_row + '][execute_time]" value="" />';
    html += '<input type="hidden" name="cron[' + cron_row + '][month]" value="" />';
    html += '<input type="hidden" name="cron[' + cron_row + '][weekday]" value="" />';
    html += '<input type="hidden" name="cron[' + cron_row + '][day]" value="" />';
    html += '<input type="hidden" name="cron[' + cron_row + '][hour]" value="" />';
    html += '<input type="hidden" name="cron[' + cron_row + '][minute]" value="" />';
    html += '</td>';
    html += '<td class="left"><input type="hidden" name="cron[' + cron_row + '][last_run]" value="" />';
    html += '</td>';
    html += '<td class="left"><input type="hidden" name="cron[' + cron_row + '][next_run]" value="" />';
    html += '</td>';
    html += '<td class="left"></td>';
    html += '<td class="right"><a onclick="$(\'#cron-row' + cron_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
    html += '</tr>';
    html += '</tbody>';

    $('#cron tfoot').before(html);

    cron_row++;
}
//--></script>
<?php echo $footer; ?>